//
//  ConnectCell.swift
//  Keyboard
//
//  Created by xinglian on 2022/12/18.
//

import UIKit

class ConnectCell: UITableViewCell {
    @IBOutlet var title: UILabel!
    @IBOutlet var line: UIView!
    @IBOutlet var mac: UILabel!
    @IBOutlet var btn: UIButton!
    var periphral:CBPeripheral?
    var block:((_ connect:Bool)->Void)?
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    @IBAction func actionForBtn(_ sender: UIButton) {
        self.block?(sender.currentTitle == LS("连接"))
    }
    private func setupBtn(_ connected:Bool){
        self.btn.textHexColor = connected ? "#15A4FF" : "#666666"
        self.btn.borderHexColor = connected ? "#15A4FF" : "#666666"
        self.btn.setTitle(connected ? LS("断开") : LS("连接"), for: .normal)
    }
     func setup() {
         guard let per = self.periphral else {return}
         self.btn.isHidden = false
         self.title.text = per.name ?? ""
         self.mac.text = per.mac
         self.setupBtn(per.state == .connected)
//         for p in BLE.connectedDevices{
//             self.setupBtn(per.state == .connected)
//        }
    }
}
